package org.example.common.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MailServiceUtil {
    @Resource
    private  JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String fromValue="532285954@qq.com";

    private String toValue="812223035@qq.com";
    public void sendMail(String from,String to,String cc,String subject,String text){
        SimpleMailMessage smm = new SimpleMailMessage();
        smm.setFrom(from);//发送者
        smm.setTo(to);//收件人
        smm.setCc(cc);//抄送人
        smm.setSubject(subject);//邮件主题
        smm.setText(text);//邮件内容
        javaMailSender.send(smm);//发送邮件
    }

    public void sendMail(String cc,String subject,String text){
        SimpleMailMessage smm = new SimpleMailMessage();
        smm.setFrom(fromValue);//发送者
        smm.setTo(toValue);//收件人
        smm.setCc(cc);//抄送人

        smm.setSubject(subject);//邮件主题
        smm.setText(text);//邮件内容
        javaMailSender.send(smm);//发送邮件
    }

    public void sendMail(String subject,String text){
        SimpleMailMessage smm = new SimpleMailMessage();
        smm.setFrom(fromValue);//发送者
        smm.setTo(toValue);//收件人
        smm.setSubject(subject);//邮件主题
        smm.setText(text);//邮件内容
        javaMailSender.send(smm);//发送邮件
    }
}
